#ifndef _ITOA_H_
#define _ITOA_H_

#include <stdlib.h>

char *zitoa(int i, char *string, int radix)
{
  int sign;
  int v;
  char *tp, *sp;
  char tmp[33];
  tp = tmp;
  
  if (radix <= 0 || radix > 36)
    return NULL;

  sign = i < 0 ? 1 : 0;
  
  if (sign)
    i = -i;
  while (i) {
    v = i % radix;
    i = i / radix;
    if (v < 10)
      *tp++ = v + '0';
    else 
      *tp++ = v - 10 + 'a';
  }
  if (string == NULL)
    string = (char *)malloc(tp - tmp + sign + 1);
  sp = string;
  if (sign)
    *sp++ = '-';
  while (tp > tmp)
    *sp++ = *--tp;
  *sp = '\0';
  return string;
}

#endif /* _ITOA_H_ */

